Use @Catch() with no argument to catch everything. Branch on instanceof HttpException — known HTTP exceptions expose their status and message to the client. Unknown errors are logged in full server-side but return a generic 500 to the client. This two-branch pattern is the production standard.
Always log the full error including stack trace for unexpected errors.
Never expose internal error details, stack traces, or DB errors to the client.
HTTP exceptions are expected client errors — surface their message and status code.
Unknown errors should always return 500 with a generic message.
Include the request path and timestamp in error responses for client-side debugging.
Imagine you need to add a global exception filter to a small NestJS service that returns a 400 response for HttpException and a generic 500 for any other error. How would you implement that filter?
If you forget to call next.handle() inside your filter's catch method, what would happen to the request lifecycle?
How would you register this filter so that it applies to all controllers without modifying each one?
You added a global filter that logs errors, but now some HttpExceptions are losing their original status codes. What could be causing that and how would you fix it?
During a load test, you notice the filter is adding significant latency. What trade‑offs would you consider to keep error handling robust yet performant?
Your team wants the filter to differentiate between client errors (4xx) and server errors (5xx) for monitoring. How would you extend the filter to support that without breaking existing behavior?
In a microservices architecture, several NestJS services share a common library for exception handling. How would you design the global filter to be reusable across services while still allowing each service to inject its own logger or monitoring client?
When deploying to Kubernetes, you see that unhandled errors sometimes cause the process to crash despite the filter. Explain why that might happen and how you would make the filter truly production‑ready.
Consider that some HttpExceptions contain sensitive data in their response payload. How would you modify the filter to sanitize responses while still preserving useful debugging info for internal logs?
Your organization is migrating legacy Express middleware to NestJS. How would you approach integrating existing error‑handling middleware with a new global NestJS exception filter to ensure a seamless transition?
Across multiple teams, there’s a need for a standardized error contract (error codes, messages, correlation IDs). How would you evolve the global filter and related infrastructure to enforce this contract at scale?
If you had to support both synchronous and asynchronous exception sources (e.g., RxJS streams, Promise rejections) in a single filter, what architectural changes would you make to keep the code maintainable and testable?